using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Gencode.PrsCommon.App;
using Gencode.Common.SQL;

namespace Personalplaner
{
    class DFerienGenerator
    {
        List<IPersonRow> row = new List<IPersonRow>();

        public DFerienGenerator(int prsID, int yearid)
        {
            addRow(prsID, yearid);
        }

		private void addRow(int prsID, int yearid)
        {
            PFerienRow ferienRow = null;
            DataView dv = getRowDV(prsID, yearid);
            try
            {
                for (int i = 0; i < dv.Count; i++)
                {
                    ferienRow = new PFerienRow();
                    ferienRow.ATID = int.Parse(dv[i].Row[0].ToString());
                    ferienRow.Name = dv[i].Row[1].ToString();
                    ferienRow.PrsID = prsID;
                    ferienRow.Monat = int.Parse(dv[i].Row[2].ToString());
					ferienRow.YearID = yearid;
					ferienRow.Year = int.Parse(DateUtil.GetYear(DateUtil.ConvertSqlToDate(dv[i].Row[3].ToString())));
                    ferienRow.SetData();

                    row.Add(ferienRow);
                }
            }
            catch (Exception e)
            {
				Gencode.Common.Util.ErrorHandler.LoggError("Ferien conversion error", "DFerienGenerator.addRow(int prsID)", e.Message.ToString());
            }
        }

		private DataView getRowDV(int prsID, int yearid)
		{
			DataView dv = SimpleQuerry.ExecuteForDataView("select ATID, Name, typwert,Von,Bis from ArbeitsTage where typ = 1 and JahrID =" + yearid);
            
            return dv;
        }

        #region Properties
        internal List<IPersonRow> Row
        {
            get { return row; }
            set { row = value; }
        }

        #endregion
    }
}
